package logic

import (
	"context"
	"shop/model/mysql"

	"shop/userrpc/internal/svc"
	"shop/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品添加
func (l *GoodAddLogic) GoodAdd(in *userrpc.GoodAddRequest) (*userrpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line

	good := &mysql.Shop{
		ShopName:   in.ShopName,
		ShopPrice:  in.ShopPrice,
		ShopCode:   int(in.ShopCode),
		ShopAuthor: in.ShopAuthor,
		UserId:     int(in.UserId),
	}

	err := good.GoodAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &userrpc.GoodAddResponse{
		ShopId: int64(good.ID),
	}, nil
}
